package com.ym.b2b.salesman.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.salesman.dao.EmBSalesmanBuyerDAO;
import com.ym.b2b.salesman.sqlbean.EmBSalesmanBuyer;
import com.zc.commons.base.Page;
import com.zc.commons.dao.ZcDao;

@Repository
public class EmBSalesmanBuyerDAOImpl<T> extends ZcDao<T> implements EmBSalesmanBuyerDAO {

    public Long searchPageEmBSalesmanBuyerNum(EmBSalesmanBuyer embsalesmanbuyer) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embsalesmanbuyer);
        return (Long) find("EM_B_SALESMAN_BUYER.searchPageEmBSalesmanBuyerNum", map);
    }

    public Page searchPageEmBSalesmanBuyer(EmBSalesmanBuyer embsalesmanbuyer, Page<EmBSalesmanBuyer> page)
                                                                                                          throws DataAccessException {
        page.setTotalRow(searchPageEmBSalesmanBuyerNum(embsalesmanbuyer));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embsalesmanbuyer);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_B_SALESMAN_BUYER.searchPageEmBSalesmanBuyer", map));
        return page;
    }

    public void insertEmBSalesmanBuyer(EmBSalesmanBuyer record) throws DataAccessException {
        insert("EM_B_SALESMAN_BUYER.insertEmBSalesmanBuyer", record);
    }

    public int updateEmBSalesmanBuyer(EmBSalesmanBuyer record) throws DataAccessException {
        int rows = update("EM_B_SALESMAN_BUYER.updateEmBSalesmanBuyer", record);
        return rows;
    }

    public EmBSalesmanBuyer searchEmBSalesmanBuyer(Long salesmanBuyerId) throws DataAccessException {
        EmBSalesmanBuyer key = new EmBSalesmanBuyer();
        key.setSalesmanBuyerId(salesmanBuyerId);
        EmBSalesmanBuyer record = (EmBSalesmanBuyer) find("EM_B_SALESMAN_BUYER.selectEmBSalesmanBuyer", key);
        return record;
    }

    public void deleteEmBSalesmanBuyer(EmBSalesmanBuyer record) throws DataAccessException {
        delete("EM_B_SALESMAN_BUYER.deleteEmBSalesmanBuyer", record);
    }

    @Override
    public void deleteMultipleEmBSalesmanBuyers(String belongIdList) {
        delete("EM_B_SALESMAN_BUYER.deleteMultipleEmBSalesmanBuyers", belongIdList);
    }
}
